package org.grayrabbit.cms.propertyset;

import java.util.HashMap;
import java.util.Map;

import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.module.propertyset.PropertySetManager;

public class DefaultCmsPropertySetFactory implements CmsPropertySetFactory {

	public PropertySet buildNoCachingPropertySet(String globalKey) {
		Map<String,Object> args = new HashMap<String,Object>();
		args.put("globalKey",globalKey);
		return  PropertySetManager.getInstance("jdbc", args);
	}

	public PropertySet buildCachingPropertySet(String globalKey,boolean bulkLoad) {
		return buildCachingPropertySet(buildNoCachingPropertySet(globalKey),bulkLoad);
	}

	public PropertySet buildCachingPropertySet(PropertySet propertySet,boolean bulkLoad) {
		if(propertySet == null){
			throw new IllegalArgumentException("PropertySet参数必须不为null!");
		}
		Map<String,Object> args1 = new HashMap<String,Object>();
		args1.put("PropertySet", propertySet);
		args1.put("bulkload", Boolean.valueOf(bulkLoad));
		return PropertySetManager.getInstance("cached", args1);
	}

	public PropertySet buildMemoryPropertySet(String globalKey) {
		PropertySet propertySet = buildNoCachingPropertySet(globalKey);
		PropertySet memoryPropertySet = PropertySetManager.getInstance("memory", new HashMap<String,Object>());
		PropertySetManager.clone(propertySet, memoryPropertySet);
		return memoryPropertySet;
	}
	
	
}
